package com.magicsoft.share.presenter.my;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.my.RankList;
import com.magicsoft.share.bean.my.UserInfo;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.my.IRecommendView;

/**
 * Created by lyf on 2017/11/23/023.
 */

public class RecommendPresenter extends BasePresenter<IRecommendView> {
    public void weekRankingForUser() {
        RetrofitUtil.getApi(APIService.class)
                .weekRankingForUser(SPUtils.getInstance().getString(SPKey.TOKEN),SPUtils.getInstance().getLong(SPKey.ID))
                .compose(new NetWorkTransformer<String>())
                .compose(new LoadingTransformer<String>(mContext))
                .subscribe(new SimpleObserver<String>(mCompositeDisposable) {
                    @Override
                    public void call(String s) {

                        getView().weekRankingForUserSuccess(s);
                    }
                });
    }

    public void userDetail() {

        RetrofitUtil.getApi(APIService.class)
                .userDetail(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID))
                .compose(new NetWorkTransformer<UserInfo>())
                .compose(new LoadingTransformer<UserInfo>(mContext))
                .subscribe(new SimpleObserver<UserInfo>(mCompositeDisposable) {
                    @Override
                    public void call(UserInfo userInfo) {

                        getView().userDetailSuccess(userInfo);
                    }
                });
    }

    public void weekRanking(int pageNum,int pageSize) {
        RetrofitUtil.getApi(APIService.class)
                .weekRanking(SPUtils.getInstance().getString(SPKey.TOKEN),pageNum,pageSize)
                .compose(new NetWorkTransformer<RankList>())
                .compose(new LoadingTransformer<RankList>(mContext))
                .subscribe(new SimpleObserver<RankList>(mCompositeDisposable) {
                    @Override
                    public void call(RankList list) {

                        getView().weekRankingSuccess(list);
                    }
                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().rankFail();
                    }
                });
    }
    public void allRanking(int pageNum,int pageSize) {
        RetrofitUtil.getApi(APIService.class)
                .allRanking(SPUtils.getInstance().getString(SPKey.TOKEN),pageNum,pageSize)
                .compose(new NetWorkTransformer<RankList>())
                .compose(new LoadingTransformer<RankList>(mContext))
                .subscribe(new SimpleObserver<RankList>(mCompositeDisposable) {
                    @Override
                    public void call(RankList list) {
                        getView().allRankingSuccess(list);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().rankFail();
                    }
                });
    }




}
